package com.yuyou.fn.educational.service.impl;

import com.github.wens.mybatisplus.examples.Example;
import com.yuyou.fn.common.util.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.yuyou.fn.educational.mapper.BaseGradeMapper;
import com.yuyou.fn.educational.entity.BaseGrade;
import com.yuyou.fn.educational.service.IBaseGradeService;
import com.github.wens.framework.service.impl.SuperServiceImpl;

import java.util.List;

/**
 *
 * BaseGrade 表数据服务层接口实现类
 *
 */
@Service
public class BaseGradeServiceImpl extends SuperServiceImpl<BaseGradeMapper, BaseGrade,Long> implements IBaseGradeService {


    @Cacheable("CacheOfGradeList")
    @Override
    public List<BaseGrade> findAllFromCache() {
        Example<BaseGrade> example = BaseGrade.createExample();
        return findListByExample(example);
    }

    @Override
    public List<String> findGradeNameByIds(List<Long> gradeIds) {
        Example<BaseGrade> example = BaseGrade.createExample();
        example.selectProperties("gradeName");
        example.createCriteria().andIn("gradeId", gradeIds );
        List<BaseGrade> gradeList = findListByExample(example);
        return BeanUtils.toList(gradeList,"gradeName");
    }

    @Override
    public String findGradeNameById(Long gradeId) {

        Example<BaseGrade> example = BaseGrade.createExample();
        example.selectProperties("gradeName");
        example.createCriteria().andEqualTo("gradeId",gradeId);
        BaseGrade baseGrade = findOneByExample(example);

        return baseGrade == null ? StringUtils.EMPTY : baseGrade.getGradeName() ;
    }

    @Override
    public BaseGrade findGradeByGradeName(String gradeName) {
        Example<BaseGrade> example = BaseGrade.createExample();
        example.createCriteria().andEqualTo("gradeName",gradeName);
        return findOneByExample(example);
    }
}